#include "ProgressBar.h"

#define TYPE ('=')

void FlushProgressBar(double total, double current)
{
    double rate = current / total;
    int int_rate = (int)(rate * 100); 
    char label[5] = "-\\|/";

    static char buffer[101] = "";

    static int num = 0;
    for(; num < int_rate; num++)
    {
        buffer[num] = TYPE;
    }

    printf("[%-100s][%.2lf%%][%c]\r", buffer, rate * 100, label[int_rate % 4]);
    fflush(stdout);
    if(rate >= 1)
    {
        printf("\n");
    }
}

void ProgressBar()
{
    char buffer[101];
    char label[5] = "-\\|/";
    memset(buffer, '\0', 101);
    int num = 0;

    for(; num <= 100; num++)
    {
        buffer[num] = TYPE;
        printf("[%-100s][%d%%][%c]\r", buffer, num, label[num % 4]);
        
        fflush(stdout);
        usleep(50000);
    }
    printf("\n");
}

